//
//@File    :	10.6_usestock2.cpp
//@Time    :	2021/08/26 22:20:40
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	using the Stock class
//
//complie with stock10.cpp

#include <iostream>
#include "10.4_stock10.h"

int main()
{
    {
    using std::cout;
    cout<<"Using constructors to create new objects\n";
    Stock stock1("NanoSmart",12,20.0);
    stock1.show();
    Stock stock2=Stock("Boffo Objects",2,2.0);
    //用构造函数创建一个临时对象,然后将该临时对象复制到stock2中,此方法将为临时对象调用析构函数
    //有些编译器可能会过一段时间删除临时对象,析构函数的调用将延迟
    stock2.show();

    cout<<"Assigning stock1 to stock2:\n";
    stock2=stock1;
    cout<<"Listening stock1 and stock2:\n";
    stock1.show();
    stock2.show();

    cout<<"Using a constructor to reset an object\n";
    stock1=Stock("Nifty Foods",10,50.0);//temp object
    cout<<"Revised stock1:\n";
    stock1.show();
    cout<<"Done\n";
    }
    system("pause");
    return 0;
}
//Stock stock2=Stock("Boffo Objects",2,2.0);
//初始化,可能会创建临时对象(也可能不会),相比于赋值,效率更高
//stock1=Stock("Nifty Foods",10,50.0);
//赋值.总会在赋值前创建一个临时对象

//列表初始化
//stock hot_tip={"Nifty Foods",10,50.0};
//Stock jock{"Sport Age Storage,Inc"};
//Stock temp {};

//const成员函数
//声明:void show() const;
//定义:void stock::show() const;
